import express from "express";

const router = express.Router();
import { 
    indexModel, 
    supplierModel, 
    goodsModel, 
    goodsTypeModel, 
    goodsTypeSizeModel,
    todostortModel
} from "../db/adminModel.js";

router.post("/addadmin", async (req, res) => {
    await indexModel.create(req.body)
    res.send({
        code: 200,
        message: "添加成功",
    })
})

router.get("/get_adminlist", async (req, res) => {
    const data = await indexModel.find()
    res.send({
        code: 200,
        message: "查询成功",
        data
    })
})

router.post("/update", async (req, res) => {
    await indexModel.updateOne({ _id: req.body._id }, req.body)
    res.send({
        code: 200,
        message: "修改成功",
    })
})

router.get("/delitem", async (req, res) => {
    await indexModel.deleteOne({ _id: req.query.id });
    res.send({
        code: 200,
        message: "删除成功",
    })
});

router.post("/addsupplier", async (req, res) => {
    await supplierModel.create(req.body)
    res.send({
        code: 200,
        message: "添加成功",
    })
})

router.get("/get_supplierlist", async (req, res) => {
    const data = await supplierModel.find()
    res.send({
        code: 200,
        message: "查询成功",
        data: data
    })
})

router.get("/get_goods", async (req, res) => {
    const data = await goodsModel.find()
    res.send({
        code: 200,
        message: "查询成功",
        data: data
    })
})

router.post("/addgoods", async (req, res) => {
    await goodsModel.create(req.body)
    res.send({
        code: 200,
        message: "添加成功",
    })
})

router.post('/addtodostort', async (req, res) => {
    await todostortModel.create(req.body)
    res.send({
        code: 200,
        message: "添加成功",
    })
})

router.get("/get_todostort", async (req, res) => {
    const data = await todostortModel.find()
    res.send({
        code: 200,
        message: "查询成功",
        data: data
    })
})


export default router;
